
(function () {
    var core = ecui,
        util = core.util,
        ui = ecui.ui,
        dom = ecui.dom;

    Object.assign(
        NS.data,
        {
        }
    );
    Object.assign(
        NS.ui,
        {
        OrderCommentSave: core.inherits(
            mao.ui.CommentSave,
            {
                onsubmit: function () {
                    if (this._oRequest) {
                        return;
                    }
                    this._oRequest = true;
                    var form = this.getInput().form;
                    if (this.action === '7') {
                        // 评论
                        ecui.esr.request(
                            'data@JSON /erp-management/venue/order/comment?id=' + form.id.value + '&comment=' + form.actionRemark.value,
                            function () {
                                this._oRequest = false;
                                var data = ecui.esr.getData('data');
                                if (data instanceof Object) {
                                    ecui.tip('warn', '评论成功');
                                    ecui.esr.getRoute('/venueOrder/calendar').CACHE = false;
                                    ecui.esr.getRoute('/venueOrder/detail').CACHE = false;
                                    ecui.esr.callRoute(util.stringFormat('/venueOrder/detail~orderSn={0}', ecui.esr.getData('orderSn')));
                                }
                            }.bind(this),
                            function () {
                                this._oRequest = false;
                            }.bind(this)
                        );
                    } else if (this.action === '6') {
                        // 删除
                        ecui.esr.request(
                            'data@FORM /erp-management/venue/order/delete?' + form.name,
                            function () {
                                this._oRequest = false;
                                var data = ecui.esr.getData('data');
                                if (data instanceof Object) {
                                    ecui.tip('warn', '删除成功');

                                    var route = ecui.esr.getRoute('/venueOrder/calendar');
                                    var monthView = ecui.get('venue-order-month-view');
                                    delete route.CACHE;

                                    if (monthView && monthView.getDate()) {
                                        route.day = monthView.getDate();
                                    }

                                    var form = document.forms.venue_order_search_form;
                                    route.venueId = form.elements.venueId.value;

                                    history.go(-1);
                                }
                            }.bind(this),
                            function () {
                                this._oRequest = false;
                            }.bind(this)
                        );
                    } else if (this.action === '5') {
                        // 编辑
                        this._oRequest = false;
                    } else {
                        // 0-撤销 1-提交 2-驳回 3-通过 4-中止
                        var tip = ['撤销', '提交', '驳回', '通过', '中止'];
                        ecui.esr.request(
                            'data@FORM /erp-management/venue/order/action?' + form.name,
                            function () {
                                this._oRequest = false;
                                var data = ecui.esr.getData('data');
                                if (data instanceof Object) {
                                    ecui.tip('warn', tip[+this.action] + '成功');
                                    if (ecui.esr.getData('initiate') === 'true') {
                                        ecui.esr.getRoute('/venueOrder/calendar').CACHE = false;
                                    } else {
                                        ecui.esr.getRoute('/venueOrder/calendar').CACHE = false;
                                    }
                                    history.go(-1);
                                }
                            }.bind(this),
                            function () {
                                this._oRequest = false;
                            }.bind(this)
                        );

                    }
                }
            }
        )
        }
    );
    ecui.esr.addRoute('detail', {
        model: ['detail@GET /erp-management/finance/play/income/${id}'],
        weight: 4,
        frame: true,
        onbeforerequest: function (context) {
        },
        onbeforerender: function (context) {
            context.ticketPriceTotal = 0;
            context.ticketMoneyTotal = 0;
            context.detail.financeIncome.ticketList.forEach(function (item) {
                context.ticketPriceTotal += Number(item.totalPrice);
                context.ticketMoneyTotal += Number(item.money);
            });
            var history = [];
            context.detail.financeIncome.histories.forEach(function (item) {
                if (item.operationType === 5) {
                    history.push(item);
                }
            });
            context.detail.financeIncome.history = history;
        },
        onafterrender: function (context) {
        }
    });
}());

